#include "Http.hpp"

void Usage(std::string programName)
{
    std::cout << "Usage: " << programName << " <port>" << std::endl;
}

void Login(HttpRequest &req, HttpResponse &resp)
{
    LOG(LogLevel::INFO) << req.Args() << " login";
    std::string text = "";
    resp.SetCode(200);
    resp.SetHeader("Content-Type", "text/html");
    text += "<html><head><title>Login</title></head><body>";
    text += "<form method='POST' action='/login'><label>Username:</label><input type='text' name='username'><br>";
    text += "<label>Password:</label><input type='password' name='password'><br>";
    text += "<input type='submit' value='Login'></form>";
    text += "</body></html>";
    resp.SetText(text);
}

int main(int argc, char* argv[])
{
    if (argc!= 2) 
        Usage(argv[0]);

    uint16_t port = std::stoi(argv[1]);
    std::unique_ptr<Http> httpsvr = std::make_unique<Http>(port);
    httpsvr->RegisterService("/login", Login);

    httpsvr->Start();

    return 0;
}